package com.eric.windows.anima;

import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.ImageView;

import com.eric.windows.R;

public class FrameTestActivity extends Activity implements View.OnClickListener {

    private ImageView animationIV;
    private AnimationDrawable animationDrawable;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_frame_test);
        animationIV = (ImageView) findViewById(R.id.animationIV);
        findViewById(R.id.button_sequence).setOnClickListener(this);
        findViewById(R.id.button_stop).setOnClickListener(this);
        findViewById(R.id.button_inverted).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.button_sequence:
                animationIV.setImageResource(R.drawable.animation_frame_sequence);
                animationDrawable = (AnimationDrawable) animationIV.getDrawable();
                animationDrawable.start();
                break;
            case R.id.button_stop:
                animationDrawable = (AnimationDrawable) animationIV.getDrawable();
                animationDrawable.stop();
                break;
            case R.id.button_inverted:
                animationIV.setImageResource(R.drawable.animation_frame_inverted);
                animationDrawable = (AnimationDrawable) animationIV.getDrawable();
                animationDrawable.start();
                break;
        }
    }
}
